package com.example.demo.controller;

import com.example.demo.model.User;
import com.example.demo.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author：naxiaozi，微信：naxiaozi
 * @date: 2025/9/8
 * @Copyright：
 */
@RestController
@RequestMapping("/api/users")
@Api(tags = "用户管理api", value = "用户管理接口")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping
    @ApiOperation(value = "获取所有用户", notes = "返回系统中所有用户的列表")
    @ApiResponse(code = 200, message = "成功获取用户列表")
    public ResponseEntity<List<User>> getAllUsers() {
        List<User> users = userService.getAllUsers();
        return ResponseEntity.ok(users);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取用户", notes = "返回指定ID的用户详细信息")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功获取用户信息"),
            @ApiResponse(code = 404, message = "用户不存在")
    })
    public ResponseEntity<User> getUserById(
            @ApiParam(value = "用户ID", example = "1", required = true)
            @PathVariable Long id) {
        User user = userService.getUserById(id);
        if (user != null) {
            return ResponseEntity.ok(user);
        }
        return ResponseEntity.notFound().build();
    }


}
